import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'list',
    component: () => import('../views/List'),
    meta: { title: '小灶派餐饮' },
  },
  {
    path: '/search',
    name: 'search',
    component: () => import('../views/Search'),
    meta: { title: '搜索商品' },
  },
  {
    path: '/order',
    name: 'order',
    component: () => import('../views/Order'),
    meta: { title: '订单中心' },
  },
  {
    path: '/orderDetail',
    name: 'orderDetail',
    component: () => import('../views/OrderDetail'),
    meta: { title: '订单详情' },
  },
  {
    path: '/about',
    name: 'about',
    component: () => import('../views/About'),
    meta: { title: '店铺详情' },
  },
  {
    path: '/settlement',
    name: 'settlement',
    component: () => import('../views/Settlement'),
    meta: { title: '提交订单' },
  },
  {
    path: '/payFinish',
    name: 'payFinish',
    component: () => import('../views/PayFinish'),
    meta: { title: '支付完成' },
  },
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

router.afterEach((to) => {
  document.title = to.meta.title || '小灶派'
})

export default router
